Skip to content

fix: Fix incorrect type check in byteArrayFormat function #546

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 10, 2025

Conversation

0xsimka
Copy link
Contributor

@0xsimka 0xsimka commented Dec 22, 2024

Description

Hello!

While working with the byteArrayFormat function, I noticed an issue with the validation logic for array elements. The original condition:

if (!(o[i] instanceof Number && o[i] >= 0 && o[i] <= 255))

...always fails for valid numbers because instanceof Number checks for the Number object type, not for primitive numbers. Since numbers in JavaScript are typically primitives, this condition doesn't behave as intended.

I've updated the check to use typeof instead, which works correctly for primitive numbers:

if (typeof o[i] !== "number" || o[i] < 0 || o[i] > 255)

This fix ensures that the function correctly validates the elements of the array.

Type of Change

  • New Page
  • Page update/improvement
  • Fix typo/grammar
  • Restructure/reorganize content
  • Update links/references
  • Other (please describe):

Checklist

  • I ran pre-commit run --all-files to check for linting errors
  • I have reviewed my changes for clarity and accuracy
  • All links are valid and working
  • Images (if any) are properly formatted and include alt text
  • Code examples (if any) are complete and functional
  • Content follows the established style guide
  • Changes are properly formatted in Markdown
  • Preview renders correctly in development environment

Contributor Information

Copy link

vercel bot commented Dec 22, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jan 10, 2025 5:46pm
documentation ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jan 10, 2025 5:46pm

Copy link

vercel bot commented Dec 22, 2024

@0xsimka is attempting to deploy a commit to the Pyth Network Team on Vercel.

A member of the Team first needs to authorize it.

Copy link
Contributor

@cprussin cprussin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the contribution!

@cprussin cprussin merged commit 814ab45 into pyth-network:main Jan 10, 2025
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants